package com.tmt.im.service.controller;

import com.tmt.im.common.pojo.ChatDataPoJo;
import com.tmt.im.service.controller.vo.ChatDataQueryRequest;
import com.tmt.im.service.controller.vo.ChatDataVo;
import com.tmt.im.service.service.ChatDataService;
import com.tmt.springboot.common.restful.IExecuteResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * 聊天信息管理接口
 *
 * @Description TODO
 * @Author wuyi
 * @Date 2024/8/6 11:26
 * @Version 1.0
 **/
@Deprecated
@Slf4j
@Tag(name = "聊天信息管理接口", description = "聊天信息相关管理接口")
@RestController
@RequestMapping("${api-url-prefix}/chat")
public class ChatDataController {

    private final ChatDataService chatDataService;

    public ChatDataController(ChatDataService ChatDataService) {
        this.chatDataService = ChatDataService;
    }

    @Operation(summary = "聊天内容接收接口",
            description = "聊天内容接收接口",
            operationId = "newChatRecord",
            parameters = {
                    @Parameter(name = "vo", description = "聊天数据对象", required = true),
                    @Parameter(name = "principal", description = "后端框架自动注入对象，不需要调用方设置", required = false)
            })
    @PostMapping("/add")
    public CompletableFuture<IExecuteResult<Boolean>> newChatRecord(ChatDataVo vo, Principal principal) {
        return chatDataService.appendChatData(vo, principal);
    }

    @Operation(summary = "撤回聊天内容接口",
            description = "撤回指定ID的聊天记录",
            operationId = "revokeChatRecord",
            parameters = {
                    @Parameter(name = "id", description = "聊天数据记录ID", required = true),
                    @Parameter(name = "principal", description = "后端框架自动注入对象，不需要调用方设置")
            })
    @PostMapping("/revoke/{id}")
    public CompletableFuture<IExecuteResult<Boolean>> revokeChatRecord(@PathVariable("id") Long id, Principal principal) {
        return chatDataService.revokeChatData(id, principal);
    }

    @Operation(summary = "查询聊天历史内容接口",
            description = "根据提交的查询请求对象查询聊天历史记录",
            operationId = "queryChatRecord",
            parameters = {
                    @Parameter(name = "queryRequest", description = "聊天历史查询请求对象", required = true),
                    @Parameter(name = "principal", description = "后端框架自动注入对象，不需要调用方设置", required = false)
            })
    @PostMapping("/query")
    public CompletableFuture<IExecuteResult<List<ChatDataPoJo>>> queryChatRecord(@RequestBody ChatDataQueryRequest queryRequest, Principal principal) {
        return chatDataService.queryChatRecord(queryRequest, principal);
    }

}
